<?php

namespace App\Http\Resources\Train\TrainOrder;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;

class PriceDetailsResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     *
     * @return array|Arrayable|JsonSerializable
     */
    public function toArray($request)
    {
        $price_details = parent::toArray($request);
        if ($request->offsetGet('show_tip') == 0) {
            unset($price_details['tip']);
        }
        $price_details['trips'] = PriceDetailsTripsResource::collection($price_details['trips']);
        return $price_details;
    }
}
